Skip to content

test: fix two flaky tests (darwin start_time regex, memstats HeapReleased drift)#2050

Merged
bwplotka merged 2 commits into
prometheus:mainfrom
kakkoyun:kakkoyun/fix-darwin-start-time
Jul 8, 2026
Merged

test: fix two flaky tests (darwin start_time regex, memstats HeapReleased drift)#2050
bwplotka merged 2 commits into
prometheus:mainfrom
kakkoyun:kakkoyun/fix-darwin-start-time

Conversation

@kakkoyun

@kakkoyun kakkoyun commented Jul 8, 2026

Copy link
Copy Markdown
Member

Two pre-existing flaky tests, each fixed independently.

Darwin process_start_time_seconds (process_collector_darwin_test.go): the check used [0-9.]{10,}, but expfmt renders large gauges in scientific notation (e.g. 1.783414e+09), whose leading digit run is only eight characters, so it failed intermittently on macOS. Changed to [0-9], matching the sibling checks in the same test; that is a presence check that does not depend on float formatting.

TestMemStatsEquivalence (go_collector_latest_test.go): the test read runtime.ReadMemStats and runtime/metrics separately and compared them within 5%, and the code itself noted it hoped no GC happened in between. HeapReleased is driven by the background scavenger and drifted between the two reads, failing on Linux arm64. It now forces a full scavenge with debug.FreeOSMemory and disables GC for the measurement window, so both reads observe the same runtime state.

Test plan: go test -race ./prometheus/... passes; TestMemStatsEquivalence run 200 times with -race is stable.

TestDarwinProcessCollector asserted process_start_time_seconds against [0-9.]{10,}, but expfmt renders large gauge values in scientific notation (for example 1.783414e+09), whose leading digit run is shorter than ten characters. The check then fails intermittently on macOS depending on the process start time. Match a leading digit like the sibling metric checks, which asserts the metric is present with a numeric value.

Signed-off-by: Kemal Akkoyun <kemal.akkoyun@datadoghq.com>
@kakkoyun kakkoyun requested review from bwplotka and vesari as code owners July 8, 2026 12:59
…ed drift

The test read runtime.ReadMemStats and runtime/metrics separately and compared them within 5%, with the code itself noting it hoped no GC ran in between. HeapReleased is driven by the background scavenger and drifted between the two reads, failing intermittently (seen on Linux arm64). Force a full scavenge with debug.FreeOSMemory and disable GC for the measurement window so both reads observe the same runtime state.

Signed-off-by: Kemal Akkoyun <kemal.akkoyun@datadoghq.com>
@kakkoyun kakkoyun changed the title test(process_collector): match scientific-notation start time on darwin test: fix two flaky tests (darwin start_time regex, memstats HeapReleased drift) Jul 8, 2026
@kakkoyun

kakkoyun commented Jul 8, 2026

Copy link
Copy Markdown
Member Author

Blocked by #2051

@bwplotka bwplotka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@bwplotka bwplotka merged commit 4cd2d3a into prometheus:main Jul 8, 2026
14 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants